package cn.jyc.ssm03.service;

import cn.jyc.ssm03.dao.CarMapper;
import cn.jyc.ssm03.dao.RentsMapper;
import cn.jyc.ssm03.pojo.Bus_rents;
import cn.jyc.ssm03.pojo.Car;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RentsService {
    @Autowired
    private RentsMapper rm;
    @Autowired
    private CarMapper cm;

    public Map<String, Object> qryRents(Integer p1, Integer p2, Bus_rents br) {
//        System.out.println(p1+"---"+p2+"---"+br);
        Map<String,Object> res = new HashMap<>();
        Page<Object> pg = PageHelper.startPage(p1, p2);
        List<Bus_rents> brs = rm.qryRents(br);
        System.out.println(brs.size());
//        System.out.println(brs.get(0));
        res.put("total",pg.getTotal());
        res.put("rows",brs);
        return res;
    }

    public Map<String, String> addRent(Bus_rents br) {
        Map<String, String> res = new HashMap<>();
        try {
            rm.addRents(br);
            cm.updCar(new Car(br.getCarnumber(),null,null,null,null,null,1,null,null));
        } catch (Exception e){
            res.put("errorMsg",e.getMessage());
        }
        return res;
    }
}
